{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 作业三：\n",
    "\n",
    "一个很大的2D矩阵，如果某点的值，由它周围某些点的值决定，例如（i，j）点 的值取当前周围8个点的平均值，如何使用MapReduce来实现 20分"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![ij](fenxi.png)\n",
    "\n",
    "分析图"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 用MapReduce来解决上述问题，以下标对作为map的key，\n",
    "\n",
    "* 遇到 ( i，j )\n",
    "* 生成 ( i-1，j-1 ),( i-1，j ),( i-1，j+1 ),( i, j+1 ),( i+1, j+1 ),( i+1, j ),( i+1, j-1 ), ( i, j-1 ) 八个周边的值。\n",
    "* 然后在 reduce 时 merge 相同的 key，并计算 value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 输入键为下标(i,j)，扫描所有下标，每扫描一个下标，生成(i-1,j)...等八个新key，值为$A[i,j]/8$，在reduce中合并所有key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
